package createobject;

//import java.io.File;
//import java.io.FileNotFoundException;
import java.util.Scanner;
import environment.Simulation;
import force.CenterMass;
import force.Gravity;
import force.Viscosity;
import force.WallRepulsion;

/**
 * @author Xi Du and Michael Deng
 *
 */
public class ForceFactory extends Factory {
///**
// * @param sim simulation class object
// * @param modelFile file object
// */
//    @Override
//    public final void loadModel(final Simulation sim, final File modelFile) {
//        try {
//            Scanner input = new Scanner(modelFile);
//            while (input.hasNext()) {
//                Scanner line = new Scanner(input.nextLine());
//                if (line.hasNext()) {
//                    String type = line.next();
//                    createsPhysicsForce(sim, line, type);
//
//                }
//            }
//            input.close();
//        } catch (FileNotFoundException e) {
//            // should not happen because File came from user selection
//            e.printStackTrace();
//        }
//    }
 
    @Override
    void createObject (Simulation sim, Scanner line, String type) {
        if (type.equals("gravity")) {
            sim.add(gravityCommand(line));
        } else if (type.equals("viscosity")) {
            sim.add(viscosityCommand(line));
        } else if (type.equals("centermass")) {
            sim.add(centermassCommand(line));
        } else if (type.equals("wall")) {
            sim.add(wallCommand(line));
        } else {
            // Do nothing
        }
        
    }
    
    
//private void createsPhysicsForce (Simulation sim, Scanner line, String type) {
//
//}
   
    
    /**
     * @param line line
     * @return gravity
     */
    private Gravity gravityCommand(final Scanner line) {
        double m1 = line.nextDouble();
        double m2 = line.nextDouble();
        return new Gravity(m1, m2);
    }
    /**
     * @param line line
     * @return Viscosity force
     */
    private Viscosity viscosityCommand(final Scanner line) {
        double m1 = line.nextDouble();
        //System.out.println(m1);
        return new Viscosity(m1);
    }
    /**
     * @param line line
     * @return center mass force
     */
    private CenterMass centermassCommand(final Scanner line) {
        double m1 = line.nextDouble();
        double m2 = line.nextDouble();
        return new CenterMass(m1, m2);
    }
    /**
     * @param line line
     * @return wall repulsion force
     */
    private WallRepulsion wallCommand(final Scanner line) {
        int m1 = line.nextInt();
        double m2 = line.nextDouble();
        double m3 = line.nextDouble();
        WallRepulsion w;
        switch(m1) {
            //one means up repulsion force
            case 1: w = new WallRepulsion(90, m2, m3);
            break;
            case 2: w = new WallRepulsion(0, m2, m3);
            break;
            case 3: w = new WallRepulsion(270, m2, m3);
            break;
            case 4: w = new WallRepulsion(180, m2, m3);
            break;
            default: w = new WallRepulsion(0, m2, m3);
            break;
        }
        return w;
    }
}
